package com.yhsimon.state;

import java.text.SimpleDateFormat;
import java.util.Date;

//模拟倒计时
public class TestThreadSleep {
    public static void countDown() throws InterruptedException {
        int num=10;
        while(true){
            System.out.println(num--);
            Thread.sleep(1000);
            if(num<0) break;
        }
    }

    public static void main(String[] args){
//        try {
//            countDown();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        //打印当前系统时间
        Date startTime=new Date(System.currentTimeMillis());
        while(true){
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(startTime));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            startTime=new Date(System.currentTimeMillis());
        }
    }
}
